# encoding=utf-8
from concurrent.futures import ThreadPoolExecutor, as_completed
from time import time


def process(fun, num, max_workers):
    with ThreadPoolExecutor(max_workers=max_workers) as t:
        begin = time()
        for page in range(int(num)):
            t.submit(fun, page)

        #     obj_list.append(obj)
        # for future in as_completed(obj_list): # 当某一个future任务执行完毕后，执行下面代码。会阻塞，等待线程完成后执行
        #     result = future.result() # 获取线程的返回结果
        #     print(result)
        times = time() - begin
        print(times)


def test(page):
    print(f'args {page}')


process(test, 10, 5)
